package com.afs.electronicforensics.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.fragment.app.FragmentTransaction;

import java.util.List;

public class TabFragmentAdapter extends FragmentStatePagerAdapter {

    private String[] titleArray;
    private List<Fragment> listFragments;
    private FragmentManager mFragmentManager;

    public TabFragmentAdapter(@NonNull FragmentManager fm) {
        super(fm);
        this.mFragmentManager = fm;
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return listFragments.get(position);
    }

    @Override
    public int getCount() {
        return listFragments.size();
    }

    @Override
    public int getItemPosition(Object object) {//最主要就是加了这个方法。
        return POSITION_NONE;
    }

    public void addFragment(Fragment fragment){
        this.listFragments.add(fragment);
    }

    public void setFragments(List<Fragment> fragments){
        this.listFragments = fragments;
    }

    public void setTitlesArr (String[] titlesArr) {
        this.titleArray = titlesArr;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titleArray[position];
    }



}
